package com.ruoyi.web.controller.gym;

import com.ny.domain.NewsDO;
import com.ny.dto.CreateGroup;
import com.ny.dto.DeleteGroup;
import com.ny.dto.NewsDTO;
import com.ny.dto.PageResult;
import com.ny.dto.RestResult;
import com.ny.dto.UpdateGroup;
import com.ny.query.NewsQuery;
import com.ny.query.QueryGroup;
import com.ny.service.NewsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.lang.Boolean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 健身资讯管理模块
 *
 * @author MSI-NB
 * @date 2025-03-08 13:14:38
 */
@Api("健身资讯管理模块")
@RequestMapping("news")
@RestController
public class NewsController {

    @Autowired
    private NewsService newsService;

    /**
     * 发布健身资讯
     *
     * @param newsDTO 健身资讯信息封装
     * @return
     */
    @RequestMapping(value = "/publish", method = RequestMethod.POST)
    @ApiOperation("发布健身资讯")
    @ResponseBody
    public RestResult<Boolean> publishNews(@RequestBody @Validated(CreateGroup.class) NewsDTO newsDTO) {
        Boolean result = newsService.publishNews(newsDTO);
        return RestResult.success(result);
    }

    /**
     * 更新健身资讯
     *
     * @param newsDTO 健身资讯信息封装
     * @return
     */
    @RequestMapping(value = "/update", method = RequestMethod.PUT)
    @ApiOperation("更新健身资讯")
    @ResponseBody
    public RestResult<Boolean> updateNews(@RequestBody @Validated(UpdateGroup.class) NewsDTO newsDTO) {
        Boolean result = newsService.updateNews(newsDTO);
        return RestResult.success(result);
    }

    /**
     * 删除健身资讯
     *
     * @param newsDTO 健身资讯信息封装
     * @return
     */
    @RequestMapping(value = "/delete", method = RequestMethod.DELETE)
    @ApiOperation("删除健身资讯")
    @ResponseBody
    public RestResult<Boolean> deleteNews(@RequestBody @Validated(DeleteGroup.class) NewsDTO newsDTO) {
        Boolean result = newsService.deleteNews(newsDTO);
        return RestResult.success(result);
    }

    /**
     * 查询所有健身资讯
     *
     * @param newsQuery 健身资讯查询参数封装
     * @return
     */
    @RequestMapping(value = "/all", method = RequestMethod.GET)
    @ApiOperation("查询所有健身资讯")
    public RestResult<PageResult<NewsDO>> getAllNews(@Validated(QueryGroup.class) NewsQuery newsQuery) {
        PageResult<NewsDO> result = newsService.getAllNews(newsQuery);
        return RestResult.success(result);
    }

    /**
     * 查询单个健身资讯
     *
     * @param newsQuery 健身资讯查询参数封装
     * @return
     */
    @RequestMapping(value = "/info", method = RequestMethod.GET)
    @ApiOperation("查询单个健身资讯")
    public RestResult<NewsDO> getNewsById(@Validated(QueryGroup.class) NewsQuery newsQuery) {
        NewsDO result = newsService.getNewsById(newsQuery);
        return RestResult.success(result);
    }
}
